package com.danny.componenttest

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.danny.componentbase.ServiceFactory
import com.danny.provider.RouterPath

@Interceptor(priority = 8, name = "登录状态拦截器")
class LoginInterceptor: IInterceptor {

    private var context: Context? = null

    override fun process(postcard: Postcard, callback: InterceptorCallback) {
        if (postcard.path == RouterPath.Share.PATH_SHARE) {
            if (ServiceFactory.serviceFactory.getAccountService().isLogin()) {
                callback.onContinue(postcard)
            } else {
                callback.onInterrupt(RuntimeException("请登录"))
            }
        } else {
            callback.onContinue(postcard)
        }
    }

    override fun init(context: Context?) {
        this.context = context
    }

}